﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Andrewl.XnaHelpers.Input
{
    public class Input_ChatPad
    {
        public KeyboardState[] previousKeyboardStates;

        public KeyboardState[] currentKeyboardStates;

        public KeyboardState[] PreviousKeyboardStates
        { get { return previousKeyboardStates; } }

        public KeyboardState[] CurrentKeyboardStates
        { get { return currentKeyboardStates; } }


        public Input_ChatPad()
        {
            previousKeyboardStates = new KeyboardState[4];
            currentKeyboardStates = new KeyboardState[4];
        }

        public void Update()
        {
            for (int i = 0; i < 4; i++)
            {
                previousKeyboardStates[i] = currentKeyboardStates[i];
                currentKeyboardStates[i] = Keyboard.GetState((PlayerIndex)i);
            }
        }


        public bool IsKeyDown(Keys key)
        {
            if (currentKeyboardStates[0].IsKeyDown(key))
                return true;
            else
                return false;
        }

        public bool IsKeyPressed(Keys key)
        {
            if (currentKeyboardStates[0].IsKeyDown(key) && previousKeyboardStates[0].IsKeyUp(key))
                return true;
            else
                return false;
        }

        public bool IsKeyUp(Keys key)
        {
            if (currentKeyboardStates[0].IsKeyUp(key))
                return true;
            else
                return false;
        }

        public Keys[] CurrentPressedKeys()
        {
            return currentKeyboardStates[0].GetPressedKeys();
        }

        public Keys[] PreviousPressedKeys()
        {
            return previousKeyboardStates[0].GetPressedKeys();
        }


        public bool IsKeyDown(PlayerIndex index, Keys key)
        {
            if (currentKeyboardStates[(int)index].IsKeyDown(key))
                return true;
            else
                return false;
        }

        public bool IsKeyPressed(PlayerIndex index, Keys key)
        {
            if (currentKeyboardStates[(int)index].IsKeyDown(key) && previousKeyboardStates[(int)index].IsKeyUp(key))
                return true;
            else
                return false;
        }

        public bool IsKeyUp(PlayerIndex index, Keys key)
        {
            if (currentKeyboardStates[(int)index].IsKeyUp(key))
                return true;
            else
                return false;
        }

        public Keys[] CurrentPressedKeys(PlayerIndex index)
        {
            return currentKeyboardStates[(int)index].GetPressedKeys();
        }

        public Keys[] PreviousPressedKeys(PlayerIndex index)
        {
            return previousKeyboardStates[(int)index].GetPressedKeys();
        }


    }
}